from appium import webdriver
from selenium.webdriver.support.wait import WebDriverWait

def connect_app(platname='Android',platversion='7.1.2',dname='****',appname='com.android.settings',appact='.Settings',port=4723):


  #设置
  desire_caps=dict(
    platformName=platname,
    platformVersion=platversion,
    deviceName=dname,
    appPackage=appname,
    appActivity=appact
  )


  ##连接appuim的服务器地址
  url='http://127.0.0.1:%s/wd/hub'%port
  ##连接appuim的服务器
  driver=webdriver.Remote(url,desire_caps)
  return driver

def get_element(driver,style,value):
  driver_wait=WebDriverWait(driver,1000)
  element=driver_wait.until(lambda driver:driver.find_element(by=style,value=value))
  return element

def input_text(element,text):
  element.clear()
  element.send_keys(text)
